package com.wondertek.common.config;

import com.github.pagehelper.PageInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @description:
 * @author: qinjianhui
 * @create: 2024-08-05 15:56
 **/
@Configuration
public class PageHelperConfig {
    @Bean
    public PageInterceptor pageInterceptor() {
        PageInterceptor pageInterceptor = new PageInterceptor();
        Properties properties = new Properties();
        // 设置数据库方言
        properties.setProperty("helperDialect", "mysql");
        // 设置分页合理化参数，默认为false。当pageNum<1会查询第一页，pageNum>pages（超过总数时），会查询最后一页
        properties.setProperty("reasonable", "true");
        // 支持通过Mapper接口方法参数来传递分页参数
        properties.setProperty("supportMethodsArguments", "true");
        // ... 你可以继续设置更多PageHelper的参数

        pageInterceptor.setProperties(properties);
        return pageInterceptor;
    }
}

